﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using System.Configuration;
using Emerson.Storage.Agent.Core;
using System.Collections;

namespace Simulator
{
    public class SimulatorService : MarshalByRefObject
    {
        public static SimulatorForm formReference;

        //the simulator app will host a .Net remoting service, waiting the connection from SimulatorAccess.
        static SimulatorService()
        {
            int simulatorPort = int.Parse(ConfigurationManager.AppSettings["SimulatorPort"]);

            TcpServerChannel channel = new TcpServerChannel("SimulatorChannel", simulatorPort);
            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownServiceType(
                   typeof(SimulatorService), "SimulatorService",
                   WellKnownObjectMode.Singleton);
        }

        public BatteryInfo GetBatteryInfo()
        {
            //converts the values in the winform controls to BatteryInfo object and return it to the caller.
            return formReference.GetBatteryInfo();
        }
    }
}
